Completed
Pull Request — develop (#224)
by
unknown
34s
created

link.js ➔ ... ➔ data.links.find   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
c 0
b 0
f 0
nc 1
dl 0
loc 3
rs 10
nop 1
1
define(['helper', 'snabbdom'], function (helper, V) {
2
  'use strict';
3
  V = V.default;
4
5
  function showStatImg(children, d, time) {
6
    var subst = {
7
      '{SOURCE_ID}': d.source.node_id,
8
      '{SOURCE_NAME}': d.source.hostname.replace(/[^a-z0-9\-]/ig, '_'),
9
      '{SOURCE_MAC}': d.source_mac,
10
      '{TARGET_ID}': d.target.node_id,
11
      '{TARGET_NAME}': d.target.hostname.replace(/[^a-z0-9\-]/ig, '_'),
12
      '{TARGET_MAC}': d.target_mac,
13
      '{TIME}': time,
14
      '{LOCALE}': _.locale()
15
    };
16
    return function(linkInfo){
17
      children.push(V.h('tr', V.h('th', { props: { rowspan: '2' } },
18
        linkInfo.name
19
      )));
20
      children.push(V.h('tr', V.h('th', { props: { rowspan: '2' } },
21
        helper.showStat(V, linkInfo, subst)
22
      )));
23
    };
24
  }
25
26
  return function (el, d, linkScale) {
27
    var self = this;
28
    var header = document.createElement('div');
29
    var table = document.createElement('table');
30
    el.appendChild(header);
31
    el.appendChild(table);
32
33
    self.render = function render() {
34
      var children = [], linkImg = [], globalImg = [];
35
      var time = d[0].target.lastseen.format('DDMMYYYYHmmss');
36
      
37
      if (config.linkInfos) {
38
        config.linkInfos.forEach(function (linkInfo) {
39
          if(linkInfo.image.indexOf('{SOURCE_MAC}') === -1) {
40
            globalImg.push(linkInfo);
41
          } else {
42
            linkImg.push(linkInfo);
43
          }
44
        });
45
      }
46
47
      header = V.patch(header, V.h('div', V.h('h2', [
48
        V.h('a', {
49
          props: { href: router.generateLink({ node: d[0].source.node_id }) }
50
        }, d[0].source.hostname),
51
        V.h('span', ' - '),
52
        V.h('a', {
53
          props: { href: router.generateLink({ node: d[0].target.node_id }) }
54
        }, d[0].target.hostname)
55
      ])));
56
57
      helper.attributeEntry(V, children, 'node.hardware', (d[0].source.model ? d[0].source.model + ' – ' : '') +
58
        (d[0].target.model ? d[0].target.model : ''));
59
      helper.attributeEntry(V, children, 'node.distance', helper.showDistance(d[0]));
60
61
      d.forEach(function (link) {
62
        children.push(V.h('tr', { props: { className: 'header' } }, [
63
          V.h('th', _.t('node.connectionType')),
64
          V.h('th', link.type)
65
        ]));
66
        helper.attributeEntry(V, children, 'node.tq', V.h('span',
67
          { style: { color: linkScale((link.source_tq + link.target_tq) / 2) } },
68
          helper.showTq(link.source_tq) + ' - ' + helper.showTq(link.target_tq))
69
        );
70
71
        linkImg.forEach(showStatImg(children, link, time));
72
      });
73
74
      globalImg.forEach(showStatImg(children, d[0], time));
75
      
76
      var elNew = V.h('table', children);
77
      table = V.patch(table, elNew);
78
      table.elm.classList.add('attributes');
79
    };
80
81
    self.setData = function setData(data) {
82
      d = data.links.filter(function (a) {
83
        return a.id === d[0].id;
84
      });
85
      self.render();
86
    };
87
    return self;
88
  };
89
});
90